1 import java.io.*;
2 import java.net.*;
3
4 public class Connection {
5 Socket client;
6 DataInputStream is;
7 DataOutputStream os;
8
9 public Connection(Socket s) throws IOException {
10 client = s;
11
12 is = new DataInputStream(client.getInputStream());
13 os = new DataOutputStream(client.getOutputStream());
14 }
15
16 public DataInputStream getInputStream() {
17 return is;
18 }
19
20 public DataOutputStream getOutputStream() {
21 return os;
22 }
23
24 public void close() {
25 try {
26 os.flush();
27 client.close();
28 } catch (IOException e) {
29 // Dont' care
30 }
31 }
32
33 public void println(String s) throws IOException {
34 print(s);
35 os.write('\n');
36 }
37
38 public void print(String s) throws IOException {
39 byte bytes[] = s.getBytes();
40
41 os.write(bytes);
42 }
43 }
|